package tiles;

import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;

public class HexMeshBuilder2 {
	
	/*
	 * Builds a mesh of side length = 1/sqrt(3)
	 */
	public Mesh buildMesh() {
		
		Mesh mesh = new Mesh();
		
		float sideLength = (float) (1/Math.sqrt(3));
		float xVal = 0.5f;
		float yVal = sideLength;
		
		Vector3f [] vertices = new Vector3f[7];
		vertices[0] = new Vector3f(0,yVal,0);
		vertices[1] = new Vector3f(-xVal,yVal/2,0);
		vertices[2] = new Vector3f(-xVal,-yVal/2,0);
		vertices[3] = new Vector3f(0,-yVal,0);
		vertices[4] = new Vector3f(xVal,-yVal/2,0);
		vertices[5] = new Vector3f(xVal,yVal/2,0);
		vertices[6] = new Vector3f(0,0,0);		
		
		
		Vector2f[] texCoord = new Vector2f[7];
//		texCoord[0] = new Vector2f(0,1);
//		texCoord[1] = new Vector2f(1,1);
//		texCoord[2] = new Vector2f(1,1);
//		texCoord[3] = new Vector2f(0,1);
//		texCoord[4] = new Vector2f(1,1);
//		texCoord[5] = new Vector2f(1,1);
//		texCoord[6] = new Vector2f(0,0);
		
		texCoord[0] = new Vector2f(0,0);
		texCoord[1] = new Vector2f(0,0);
		texCoord[2] = new Vector2f(0,0);
		texCoord[3] = new Vector2f(0,0);
		texCoord[4] = new Vector2f(0,0);
		texCoord[5] = new Vector2f(0,0);
		texCoord[6] = new Vector2f(1,0);
		
//		texCoord[0] = new Vector2f(0,yVal);
//		texCoord[1] = new Vector2f(-xVal,yVal/2);
//		texCoord[2] = new Vector2f(-xVal,-yVal/2);
//		texCoord[3] = new Vector2f(0,-yVal);
//		texCoord[4] = new Vector2f(xVal,-yVal/2);
//		texCoord[5] = new Vector2f(xVal,yVal/2);
//		texCoord[6] = new Vector2f(0,0);
		
		
		int [] indexes = { 0,1,6, 1,2,6, 2,3,6, 3,4,6, 4,5,6, 0,6,5 };
		
		
		mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
		mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
		mesh.setBuffer(Type.Index,    1, BufferUtils.createIntBuffer(indexes));
		mesh.updateBound();
		mesh.setStatic();
		
		
		
		
		
		return mesh;
	}

}
